Support IOS setup in AppDelegate.m#394
Conversation
|
I did the same in my PR #382 (comment) |
That pull request is really difficult to review because you changed indentation so many places in the file ;) |
|
Yep, but that is just indentation and in should look better in a good diff viewer. I do that because I am convinced that more readable and more intuitive code would be better for everyone. |
|
To be honest it doesn't matter what you think the indentation in the current project; it's good practice not to just go changing it, especially within a PR for another feature |
|
I also don't care what you are thinking. I just prefer have better code in the repo that I need to use and that's it. |
|
That's a great way to talk to one of the people that would approve your PR... |
…ionEventListenerAdded variable
| + (BOOL)isCallActive:(NSString *)uuidString; | ||
|
|
||
| + (void)setup:(NSDictionary *)options; | ||
|
|
There was a problem hiding this comment.
Expose a static method to call setup from AppDelegate.m
| if (self = [super init]) { | ||
| _isStartCallActionEventListenerAdded = NO; | ||
| _delayedEvents = [NSMutableArray array]; | ||
| if (_delayedEvents == nil) _delayedEvents = [NSMutableArray array]; |
There was a problem hiding this comment.
init is called repeatedly, deleting any events queued up here. This avoids that.
| name, @"name", | ||
| body, @"data", | ||
| nil | ||
| ]; |
There was a problem hiding this comment.
body can be null for certain events, such as RNCallKeepDidActivateAudioSession which will fire before the bridge is up if answering a call really quickly!
| supportsDTMF:(BOOL)supportsDTMF | ||
| supportsGrouping:(BOOL)supportsGrouping | ||
| supportsUngrouping:(BOOL)supportsUngrouping) | ||
| supportsUngrouping:(BOOL)supportsUngrouping) |
There was a problem hiding this comment.
Whatever was sitting at the end of this line, xcode insists on deleting it when I save the file 🤷♂️
There was a problem hiding this comment.
whitespace is the devil
|
Upon further investigation, it might be sufficient to just call [RNCallKeep initCallKitProvider] instead of setup, considering it's using I'll make some testing and amend the PR if that's the case. Edit: |
|
@jonastelzio can you make changes to the README too? Other than that I've confirmed these changes work in a project so I'd be happy to approve once theres docs on using setup in app delegate |
Can do! |
… only be ignored if initial setup was done in AppDelegate.m
26c6990 to
e5607f5
Compare
| RNCallKeep *callKeep = [RNCallKeep allocWithZone: nil]; | ||
| [callKeep setup:options]; | ||
| isSetupNatively = YES; | ||
| } |
There was a problem hiding this comment.
Simply allocate the singleton and call setup in there, setting isSetupNatively makes the library ignore further calls to setup from react native.
| NSLog(@"[RNCallKeep][setup] already setup"); | ||
| RCTLog(@"[RNCallKeep][setup] already setup in native code"); | ||
| #endif | ||
| return; |
There was a problem hiding this comment.
If we've already initialized from AppDelegate.m, we ignore further calls to setup from React Native.
|
@danjenkins I've added documentation and changed the behavior so we ONLY prevent repeated calls to .setup from react native IF the module is initially setup from native code. This way this push will never change any existing functionality. |
|
Any updates on this? It would be great if this PR will be merged. |
|
Thanks @jonastelzio ! |
On IOS, CallKit doesn't get it's delegate registered before actively calling .setup from react native, meaning that we'll never get any didLoadWithEvents fired for events such as answer and end, since CallKit simply isn't delegated to callkeep prior answering the call.
This PR exposes setup so it can be called from AppDelegate.m, allowing us to catch these events as soon as they happen.
Example of how to perform setup during AppDelegate initialization: